import React, { Component } from 'react'

export default class Count extends Component {
	state = {username:'老刘'}

	render() {
		// console.log('CountUI收到的props是：',this.props)
		return (
			<div>
				<h2>当前求和为：{this.props.sum}</h2>
				<h4>我最爱的男人是:{this.state.username}</h4>
				<select ref={ c => this.selectNumber = c}>
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
				</select>&nbsp;
				<button onClick={this.increment}>+</button> <br/><br/>
				<button onClick={this.decrement}>-</button> <br/><br/>
				<button onClick={this.incrementIfOdd}>当前和为奇数再+</button> <br/><br/>
				<button onClick={this.incrementWait}>等一等再加</button> <br/><br/>
				<button onClick={this.test}>就是想加，但不知加几？（具体加几，看服务器）</button>
			</div>
		)
	}

	//加法
	increment = ()=>{
		//获取用户的输入
		const {value} = this.selectNumber
		//调用容器组件传递过来的jia方法
		this.props.jia(value*1)
	}

	//减法
	decrement = ()=>{
		//获取用户的输入
		const {value} = this.selectNumber
		this.props.jian(value*1)
	}

	//奇数再加
	incrementIfOdd = ()=>{
		//获取用户的输入
		const {value} = this.selectNumber
		if(this.props.sum%2){
			this.props.jia(value*1)
		}
	}

	//等一等再加
	incrementWait = ()=>{
		//获取用户的输入
		const {value} = this.selectNumber
		this.props.dydJia(value*1)
	}

	test = ()=>{
		this.props.serverJia()
	}
}
